<template>
  <div>
    <f-form ref='form' :action='api.payment' :form-key='this.formItem.paymentId' :handlerName='handlerName'>
      <div>
        <f-form-item label='结算范围' type='radio' :required='true' data-type='number' name='settleType' :value.sync='formItem.settleType' :data='api.busCommon.settleType' @change='settleTypeChange' />
        <f-form-item label='结算金额' name='totalSettleAmount' disabled data-type='number' :required='true' :value.sync='formItem.totalSettleAmount' />
<!--        <f-form-item label='收款人' name='saleManName' disabled :required='true' :value.sync='formItem.saleManName' />
        <f-form-item label='收款账户' placeholder='请选择收款账户' name='bankName' :readOnly='true' :required='true' :value.sync='formItem.bankName' :trigger-change='true'>
          <a-tooltip slot='addonBefore' placement='top' title='点击图标选择收款账户'>
            <a-icon type='team' style='cursor:pointer' @click='openSaleManBankModal' />
          </a-tooltip>
        </f-form-item>-->
        <f-form-item label='备注' name='remark' :value='formItem.remark' />
      </div>
    </f-form>
    <select-sale-man-bank-modal ref='saleManBankModal' @onSelectChange='onSelectSaleManBankChange'></select-sale-man-bank-modal>
  </div>
</template>
<script>

import api from "../../../../js/api"
import SelectInvoiceModal from "@/views/module/haiying/components/select_invoice_modal"
import SelectSaleManBankModal from "@/views/module/haiying/components/select_saleman_bank_modal"

export default {
  name: "SettleApply",
  components: { SelectSaleManBankModal, SelectInvoiceModal },
  data() {
    let me = this
    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {},
      loaded: false,
      handlerName: "hySettleApplyPaymentSaveHandler",
      saleManName:null,
      selectIds: "",
      formItem: this.getFormItem()
    }
  },
  created() {
  },
  computed: {},
  methods: {
    getFormItem() {
      return {
        deptSettleInvoiceId: "",
        settleType: 1,
        saleManName:null,
        amountDate: null,
        totalSettleAmount: 0,
        remark: ""
      }
    },
    setData(data) {
      if (data.selectIds) {
        this.$refs.form.resetFields()
        this.formItem = this.getFormItem()
        this.selectIds = data.selectIds
        this.getSettleApplyInfo()
      }
    },
    /**
     * 获取支付信息
     */
    getSettleApplyInfo() {
      this.http.get(this, {
        url: this.api.payment.getSettleApplyInfo,
        params: {
          settleIds: this.selectIds,
          settleType: this.formItem.settleType
        },
        success: (me, data) => {
          this.$nextTick(() => {
            this.formItem = data
            if(data.totalSettleAmount){
              //this.formItem.saleManName=data.saleManName;
              //this.formItem.saleManId=data.saleManId;
              //this.$refs.form.getForm().setFieldsValue({ "saleManName": data.saleManName })
              this.$refs.form.getForm().setFieldsValue({ "totalSettleAmount": data.totalSettleAmount })
            }else{
              //this.formItem.saleManId="";
              //this.$refs.form.getForm().setFieldsValue({ "saleManName": "" })
              this.$refs.form.getForm().setFieldsValue({ "totalSettleAmount": null })
              this.formItem.totalSettleAmount=null;
            }
            this.$forceUpdate()
          })
        }
      })
    },
    /**
     * 结算范围选择
     */
    settleTypeChange(val) {
      this.formItem.settleType = val
      this.getSettleApplyInfo()
    },
    /**
     * 选择收款账户
     */
    openSaleManBankModal() {
      this.$refs["saleManBankModal"].open({
        saleManId:this.formItem.saleManId
      })
    },
    /**
     * 收款账户选择回调
     */
    onSelectSaleManBankChange(selectedRowKeys, selectedRows) {
      this.$refs.form.getForm().setFieldsValue({ "bankName": selectedRows[0].bankName })
      this.formItem.bankId = selectedRowKeys[0]
      this.$forceUpdate()
    },
    handleSubmit() {
      this.$refs["form"].submit({
        selectIds: this.selectIds,
        saleManId: this.formItem.saleManId,
        bankId: this.formItem.bankId
      }, this.handleSuccess)
    },
    handleSuccess() {
      this.$emit("closeDrawer", false)
    }
  }
}
</script>
